/**********************************************************
 * CreateDepositsReportAction.java.java
 * Created by Ashutosh
 * Last modified Date: Sep 18, 2008 10:46:43 AM by Ashutosh
 * Revision: <svn revision #>
 * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 **********************************************************/

package com.printeverywhere.action;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.opensymphony.xwork2.ActionSupport;
import com.printeverywhere.delegator.CommonFunctionDelegator;
import com.printeverywhere.delegator.UserServiceDelegator;
import com.printeverywhere.dto.Deposits;

// TODO: Auto-generated Javadoc
/**
 * The Class CreateDepositsReportAction.
 */
public class CreateDepositsReportAction extends AdminEngineManagement implements ServletRequestAware {

	/** Logger for this class. */
	private static final Logger logger = Logger.getLogger(CreateDepositsReportAction.class);

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;

	private HttpServletRequest request;

	private List<Deposits> depositsList = new ArrayList<Deposits>();

	private Date fromDate;

	private Date toDate;

	/* (non-Javadoc)
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	public String execute() throws Exception{
		if (logger.isDebugEnabled()) {
			logger.debug("execute() - start"); //$NON-NLS-1$
		}

		if (logger.isDebugEnabled()) {
			logger.debug("execute() - end"); //$NON-NLS-1$
		}
		return SUCCESS;
	}

	public String createDepositsReport() throws Exception {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		this.fromDate = simpleDateFormat.parse(request.getParameter("fromDate").substring(0, 10));
		this.toDate = simpleDateFormat.parse(request.getParameter("toDate").substring(0, 10));

		List<Criterion> criterionList = new ArrayList<Criterion>();
		criterionList.add(Restrictions.ge("depositDate", this.fromDate));
		criterionList.add(Restrictions.le("depositDate", this.toDate));
		criterionList.add(Restrictions.gt("amount", 0d));
		this.depositsList = (List<Deposits>) CommonFunctionDelegator.getObjectsByCriterion(criterionList, Order.asc("user.id"), null, Deposits.class);
		return SUCCESS;
	}

	public List<Deposits> getDepositsList() {
		return depositsList;
	}

	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	public Date getFromDate() {
		return fromDate;
	}

	public Date getToDate() {
		return toDate;
	}
}